<?php

class image_process extends Admin_Controller
{
	
	
	function saveItem()
	{
		global $CI;
		
		// model
		/*
		$CI->load->module_model('image.image_detail_model');
		
		// validate
		$CI->load->library('form_validation');
        $CI->form_validation->set_rules('name', 'Name', 'trim|required');
        if ($CI->form_validation->run() == FALSE)
		{
			// message
			$CI->image_detail_model->cache->add('msg', $CI->lang->line('detail_cannot_save')." : ".$CI->form_validation->error_string());
			$CI->course_detail_model->cache->add('post', $_POST);

			// go to original page
			redirect($CI->image_detail_model->url_prefix.'/'.$CI->image_detail_model->start.'/'.$CI->image_detail_model->item);
		}
		*/
		// upload
		$CI->load->module_language('upload_images.upload_images');
		$CI->load->library("fckeditor");
		$path = $CI->fckeditor->UploadPath.'/images';		
		//$path = str_replace(base_url(),"./",$path);
        $path = rtrim($_SERVER['DOCUMENT_ROOT'], "/").$path;
		if ($_FILES['local_file']['tmp_name'])
		{
			//$CI->load->module_model('image.display_image_model');
			//$path = $CI->display_image_model->path();
			
			$config['upload_path'] = $path;
			$config['allowed_types'] = 'gif|jpg|jpeg|png';
			$config['max_width'] = '1024';
			$config['max_height'] = '768';			
			$config['max_size'] = '1024';
			$config['max_filename'] = '24';
			$CI->load->library('upload', $config);
			if ($CI->upload->do_upload('local_file'))
			{
				set_flash_message(lang('upload_success'));
			} else {
				set_flash_message($CI->lang->line('detail_cannot_save')." : ".$CI->upload->display_errors());
			}
		}
		// go to original page
		redirect("admin_ajax/upload_images.upload_images.lists");
	}		
}

?>